package cn.iocoder.yudao.module.jifenyuan.controller.admin.usercurrentroom;

import cn.iocoder.yudao.module.jifenyuan.controller.app.usercurrentroom.vo.AppUserCurrentRoomRespVO;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;

import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog;
import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.*;

import cn.iocoder.yudao.module.jifenyuan.controller.admin.usercurrentroom.vo.*;
import cn.iocoder.yudao.module.jifenyuan.dal.dataobject.usercurrentroom.UserCurrentRoomDO;
import cn.iocoder.yudao.module.jifenyuan.convert.usercurrentroom.UserCurrentRoomConvert;
import cn.iocoder.yudao.module.jifenyuan.service.usercurrentroom.UserCurrentRoomService;

@Tag(name = "管理后台 - 查看当前所在房间")
@RestController
@RequestMapping("/jifenyuan/user-current-room")
@Validated
public class UserCurrentRoomController {

    @Resource
    private UserCurrentRoomService userCurrentRoomService;

    @PostMapping("/create")
    @Operation(summary = "创建查看当前所在房间")
    @PreAuthorize("@ss.hasPermission('jifenyuan:user-current-room:create')")
    public CommonResult<Long> createUserCurrentRoom(@Valid @RequestBody UserCurrentRoomCreateReqVO createReqVO) {
        return success(userCurrentRoomService.createUserCurrentRoom(UserCurrentRoomConvert.INSTANCE.convert(createReqVO)));
    }

    @PutMapping("/update")
    @Operation(summary = "更新查看当前所在房间")
    @PreAuthorize("@ss.hasPermission('jifenyuan:user-current-room:update')")
    public CommonResult<Boolean> updateUserCurrentRoom(@Valid @RequestBody UserCurrentRoomUpdateReqVO updateReqVO) {
        userCurrentRoomService.updateUserCurrentRoom(UserCurrentRoomConvert.INSTANCE.convert(updateReqVO));
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除查看当前所在房间")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('jifenyuan:user-current-room:delete')")
    public CommonResult<Boolean> deleteUserCurrentRoom(@RequestParam("id") Long id) {
        userCurrentRoomService.deleteUserCurrentRoom(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得查看当前所在房间")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('jifenyuan:user-current-room:query')")
    public CommonResult<AppUserCurrentRoomRespVO> getUserCurrentRoom(@RequestParam("id") Long id) {
        UserCurrentRoomDO userCurrentRoom = userCurrentRoomService.getUserCurrentRoom(id);
        return success(UserCurrentRoomConvert.INSTANCE.convert(userCurrentRoom));
    }

    @GetMapping("/list")
    @Operation(summary = "获得查看当前所在房间列表")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    @PreAuthorize("@ss.hasPermission('jifenyuan:user-current-room:query')")
    public CommonResult<List<AppUserCurrentRoomRespVO>> getUserCurrentRoomList(@RequestParam("ids") Collection<Long> ids) {
        List<UserCurrentRoomDO> list = userCurrentRoomService.getUserCurrentRoomList(ids);
        return success(UserCurrentRoomConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @Operation(summary = "获得查看当前所在房间分页")
    @PreAuthorize("@ss.hasPermission('jifenyuan:user-current-room:query')")
    public CommonResult<PageResult<AppUserCurrentRoomRespVO>> getUserCurrentRoomPage(@Valid UserCurrentRoomPageReqVO pageVO) {
        PageResult<UserCurrentRoomDO> pageResult = userCurrentRoomService.getUserCurrentRoomPage(UserCurrentRoomConvert.INSTANCE.convert(pageVO));
        return success(UserCurrentRoomConvert.INSTANCE.convertPage(pageResult));
    }



}
